package tools;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

public class instantiation {
    public instantiation() {
    }
    //symbol为决定当前session化的内容：1-为用户
    public static void setSeesion(ResultSet rs, int symbol, HttpServletRequest request, HttpServletResponse response) throws SQLException {
        HttpSession session = request.getSession(true);
        Map<String,String> map = new HashMap<String,String>();
        if(symbol == 1)
        {
            System.out.println(rs.getString("username"));
            map.put("id",rs.getString("use_id"));
            map.put("用户名",rs.getString("username"));
            map.put("password",rs.getString("password"));
            map.put("phone",rs.getString("phone"));
            map.put("img",rs.getString("img"));
            map.put("sex",rs.getString("sex"));
            map.put("role",rs.getString("role"));
            map.put("address",rs.getString("address"));
            map.put("dgutnumber",rs.getString("dgutnumber"));
            session.setAttribute("userName", map);
            session.setAttribute("token", null);
            session.setAttribute("userBone", "暂时无绑定信息");
        }
        if(symbol == 2)
        {
            map.put("学号",rs.getString("username"));
            map.put("姓名",rs.getString("name"));
            map.put("职位",rs.getString("type"));
            session.setAttribute("userBone", map);
        }
    }
}
